<template>
  <div class="detail-header">
    <router-link
      to="/"
      tag="div"
      class="header-abs"
      v-show="showABS"
    >
      <span class="iconfont">&#xe624;</span>
    </router-link>
    <div
      class="header-fixed"
      v-show="!showABS"
      :style="opacityStyle"
    >
      景点详情
      <router-link to="/" tag="div" class="iconfont header-back">
        &#xe624;
      </router-link>
    </div>
  </div>
</template>

<script>
  export default {
    name: "DetailHeader",
    data (){
      return {
        showABS:true,
        opacityStyle:{
          opacity:0
        }
      }
    },
    methods:{
      handleScroll(){
        // console.log('okkkk');
        let top = document.documentElement.scrollTop;
        let opacity = top/140;
        if(top > 60){
          opacity = opacity>1 ? 1:opacity;
          this.opacityStyle = { opacity };
          this.showABS = false;
        }else{
          this.showABS = true;
        }
      }
    },
    activated (){
      window.addEventListener('scroll',this.handleScroll);
    },
    deactivated(){
      window.removeEventListener('scroll',this.handleScroll);
    }
  }
</script>

<style scoped lang="stylus">
  @import '~styles/varibles.styl'
  .header-abs
    position:absolute
    top:.2rem
    left:.2rem
    width:.6rem
    height:.6rem
    line-height:.6rem
    text-align:center
    border-radius:.3rem
    background: rgba(0,0,0,0.7);
    color:#fff
    font-size:.28rem
  .header-fixed
    overflow:hidden
    height:$headerHeight
    line-height:$headerHeight
    text-align:center
    color: #fff
    background: $bgColor
    font-size:.32rem
    position:fixed
    top:0
    left:0
    right:0
    z-index:999
    .header-back
      position:absolute
      top:0
      left:0
      width:.64rem
      text-align:center
</style>
